import json
import re

reParam = re.compile(r'^[A-Z0-9]{2,}$')
reMML = re.compile(r'[A-Z]{3,} [A-Z0-9]{2,}')
reTitle = re.compile(r'[（,/(]([A-Z]{3,} [A-Z0-9_]{2,})[）,\)]$')
reT = [
    r'本参数来源于([A-Z0-9]+ [A-Z0-9]+)+[/]{0,1}([A-Z0-9]+ [A-Z0-9]+)*命令',
    r'本参数来自于([A-Z0-9]+ [A-Z0-9]+)+[/]{0,1}([A-Z0-9]+ [A-Z0-9]+)*命令',
    r'本参数需要与([A-Z0-9]+ [A-Z0-9]+)[/]{0,1}([A-Z0-9]+ [A-Z0-9]+)*命令.+保持一致',
    r'使用([A-Z0-9]+ [A-Z0-9]+)[/]{0,1}([A-Z0-9]+ [A-Z0-9]+)*命令',
    r'通过([A-Z0-9]+ [A-Z0-9]+)[/]{0,1}([A-Z0-9]+ [A-Z0-9]+)*命令',
    r'和([A-Z0-9]+ [A-Z0-9]+)[/]{0,1}([A-Z0-9]+ [A-Z0-9]+)*.*中配置',
    r'通过命令([A-Z0-9]+ [A-Z0-9]+)[/]{0,1}([A-Z0-9]+ [A-Z0-9]+)*.*',
    r'配置了([A-Z0-9]+ [A-Z0-9]+)[/]{0,1}([A-Z0-9]+ [A-Z0-9]+)*.*'
]
reS = [re.compile(x) for x in reT]
rmHTML = re.compile(r'<[^>]+>',re.S)
reALM = re.compile(r'ALM-([0-9]{4,}) (.+)')

def dump_to_json(obj,filename='MAPPING.json'):
    f = open(filename,'w',encoding='utf-8')
    json.dump(obj,f,ensure_ascii=False)
    f.close()


def get_back_data(jsonfile = 'MAPPING.json'):
    try:
        with open(jsonfile,'r',encoding='utf-8') as f:
            data = json.load(f)
            if data:
                print('%s共载入了%d条数据'%(jsonfile,len(data)))
            return data
    except FileNotFoundError as e:
        print("没有找到",jsonfile)


